package com.foreveross.bsl.mam.app.application.impl;

import java.util.List;

import javax.inject.Named;
import javax.ws.rs.PathParam;

import com.foreveross.bsl.common.utils.bean.BeanHelper;
import com.foreveross.bsl.common.utils.enums.OperatEnum;
import com.foreveross.bsl.mam.app.application.DefindApplication;
import com.foreveross.bsl.mam.app.application.vo.AppVersionVo;
import com.foreveross.bsl.mam.app.application.vo.DefindVo;
import com.foreveross.bsl.mam.model.app.domain.Defind;

@Named("defindApplication")
public class DefindApplicationImpl implements DefindApplication {

	@Override
	public DefindVo saveEntity(DefindVo entity) {
		// TODO Auto-generated method stub
		Defind defind = new Defind();
		BeanHelper.copyProperties(defind, entity);
		defind = (Defind) defind.save();
		BeanHelper.copyProperties(entity, defind);
		return entity;
	}

	@Override
	public DefindVo updateEntity(String id, DefindVo entity) {
		// TODO Auto-generated method stub
		Defind defind = new Defind();
		BeanHelper.copyProperties(defind, entity);
		defind = (Defind) defind.save();
		BeanHelper.copyProperties(entity, defind);
		return entity;
	}

	@Override
	public void deleteEntity(String id) {
		// TODO Auto-generated method stub

	}

	@Override
	public DefindVo getEntity(String id) {
		Defind defind = new Defind();
		DefindVo entityVo = new DefindVo();
		Defind def = (Defind) defind.findOne(id);
		if (def != null) {
			BeanHelper.copyProperties(entityVo, def);
			return entityVo;
		}
		return entityVo;
	}

	@SuppressWarnings("unchecked")
	@Override
	public DefindVo getEntityByAppId(String platform, String version,
			String appId) {
		// TODO Auto-generated method stub
		Defind defind = new Defind();
		List<Defind> defindlsit = defind.findListByProperty(new String[] {
				"platform", "version", "appId" }, new OperatEnum[] {
				OperatEnum.EQ, OperatEnum.EQ, OperatEnum.EQ }, new String[] {
				platform, version, appId });
		if (defindlsit != null && defindlsit.size() > 0) {
			DefindVo entityVo = new DefindVo();
			BeanHelper.copyProperties(entityVo, defindlsit.get(0));
			return entityVo;
		}
		return null;
	}

	@Override
	public void deleteByAppId(String platform, String version, String appId) {
		// TODO Auto-generated method stub
		Defind defind = new Defind();
		defind.deleteByProperty(
				new String[] { "platform", "version", "appId" },
				new OperatEnum[] { OperatEnum.EQ, OperatEnum.EQ, OperatEnum.EQ },
				new String[] { platform, version, appId });
	}

}
